package com.ruoyi.web.controller.equipment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.equipment.EquipmentBxwx;
import com.ruoyi.system.service.IEquipmentBxwxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 设备报修维修Controller
 *
 * @author ruoyi
 * @date 2023-04-18
 */
@Api(tags = "设备报修维修")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/equipment/repair" )
public class EquipmentBxwxController extends BaseController {

    private final IEquipmentBxwxService iEquipmentBxwxService;

    /**
     * 查询设备报修维修列表
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:list')")
    @ApiOperation(value = "查询设备报修维修列表")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentBxwx equipmentBxwx)
    {
        startPage();
        LambdaQueryWrapper<EquipmentBxwx> lqw = new LambdaQueryWrapper<EquipmentBxwx>();
        if (StringUtils.isNotBlank(equipmentBxwx.getBxNumber())){
            lqw.eq(EquipmentBxwx::getBxNumber ,equipmentBxwx.getBxNumber());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getEquipmentCode())){
            lqw.eq(EquipmentBxwx::getEquipmentCode ,equipmentBxwx.getEquipmentCode());
        }
        if (equipmentBxwx.getEquipmentId() != null){
            lqw.eq(EquipmentBxwx::getEquipmentId ,equipmentBxwx.getEquipmentId());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getEquipmentName())){
            lqw.like(EquipmentBxwx::getEquipmentName ,equipmentBxwx.getEquipmentName());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getEquipmentType())){
            lqw.eq(EquipmentBxwx::getEquipmentType ,equipmentBxwx.getEquipmentType());
        }
        if (equipmentBxwx.getEquipmentTypeId() != null){
            lqw.eq(EquipmentBxwx::getEquipmentTypeId ,equipmentBxwx.getEquipmentTypeId());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getEquipmentWz())){
            lqw.eq(EquipmentBxwx::getEquipmentWz ,equipmentBxwx.getEquipmentWz());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getFaultType())){
            lqw.eq(EquipmentBxwx::getFaultType ,equipmentBxwx.getFaultType());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getFaultDescribe())){
            lqw.eq(EquipmentBxwx::getFaultDescribe ,equipmentBxwx.getFaultDescribe());
        }
        if (equipmentBxwx.getUrgency() != null){
            lqw.eq(EquipmentBxwx::getUrgency ,equipmentBxwx.getUrgency());
        }
        if (equipmentBxwx.getStatus() != null){
            lqw.eq(EquipmentBxwx::getStatus ,equipmentBxwx.getStatus());
        }
        if (StringUtils.isNotBlank(equipmentBxwx.getServiceContent())){
            lqw.eq(EquipmentBxwx::getServiceContent ,equipmentBxwx.getServiceContent());
        }
        List<EquipmentBxwx> list = iEquipmentBxwxService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出设备报修维修列表
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:export')" )
    @Log(title = "设备报修维修" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(EquipmentBxwx equipmentBxwx) {
        LambdaQueryWrapper<EquipmentBxwx> lqw = new LambdaQueryWrapper<EquipmentBxwx>(equipmentBxwx);
        List<EquipmentBxwx> list = iEquipmentBxwxService.list(lqw);
        ExcelUtil<EquipmentBxwx> util = new ExcelUtil<EquipmentBxwx>(EquipmentBxwx. class);
        return util.exportExcel(list, "EquipmentRepair" );
    }

    /**
     * 获取设备报修维修详细信息
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:query')" )
    @GetMapping(value = "/{wxId}" )
    @ApiOperation(value = "获取设备报修维修详细信息")
    public AjaxResult getInfo(@PathVariable("wxId" ) Long wxId) {
        EquipmentBxwx equipmentBxwx=iEquipmentBxwxService.getByIdWithImg(wxId);
        return AjaxResult.success(equipmentBxwx);
    }

    /**
     * 新增设备报修维修
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:add')" )
    @ApiOperation(value = "新增设备报修维修")
    @Log(title = "设备报修维修" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentBxwx equipmentBxwx) {
        int result=iEquipmentBxwxService.add(equipmentBxwx);
        return toAjax(result);
    }

    /**
     * 修改设备报修维修
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:edit')" )
    @ApiOperation(value = "修改设备报修维修")
    @Log(title = "设备报修维修" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentBxwx equipmentBxwx) {
        return toAjax(iEquipmentBxwxService.updateById(equipmentBxwx) ? 1 : 0);
    }

    /**
     * 删除设备报修维修
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:remove')" )
    @ApiOperation(value = "删除设备报修维修")
    @Log(title = "设备报修维修" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{wxIds}" )
    public AjaxResult remove(@PathVariable Long[] wxIds) {
        return toAjax(iEquipmentBxwxService.removeByIds(Arrays.asList(wxIds)) ? 1 : 0);
    }
    /**
     * 执行维修
     */
    //@PreAuthorize("@ss.hasPermi('repair:EquipmentRepair:execute')" )
    @ApiOperation(value = "执行维修")
    @Log(title = "执行维修" , businessType = BusinessType.UPDATE)
    @PutMapping("/executeRepair")
    public AjaxResult executeRepair(@RequestBody EquipmentBxwx equipmentBxwx) {
        int result =iEquipmentBxwxService.executeRepair(equipmentBxwx);
        return toAjax(result);
    }
}
